package com.shopping.userside.goods.controller;

import com.shopping.entity.Result;
import com.shopping.entity.StatusCode;
import com.shopping.userside.goods.pojo.Store;
import com.shopping.userside.goods.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * (Goods)表控制层
 *
 * @author xusai
 * @since 2020-06-02 10:50:32
 */
@RestController
@RequestMapping("/store")
public class StoreController {
    /**
     * 服务对象
     */
    @Autowired
    private StoreService storeService;

    /**
     * 查询所有店铺数据
     *
     * @param
     * @return 所有店铺数据
     */
    @GetMapping("/findAll")
    public Result findAll() {
        List<Store> storeList = storeService.queryAll();
        if (storeList != null && storeList.size() > 0) {
            return new Result(true, 20000, "查询成功", storeList);
        }
        return new Result(false, 20001, "查询失败");
    }

    /**
     * 根据id查询店铺对应数据
     *
     * @param
     * @return 对应店铺数据
     */
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable("id") int sid) {
        Store store = storeService.queryById(sid);
        if (store != null) {
            return new Result(true, StatusCode.OK, "查询成功", store);
        }
        return new Result(false, StatusCode.ERROR, "查询失败");
    }
}